/*
 * @Descripttion : QianFox让数字化营销更简单
 * @Author       : QianFox Team
 * @Date         : 2024-03-05 09:11:00
 * @Version      : V1.08
 * @Copyright    : ©2021-现在 贵州黔狐科技股份有限公司 版权所有
 * @LastEditors  : QianFox Team
 * @LastEditTime : 2024-07-29 10:05:25
 */
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
    entry: {
        foxuiJs: './src/js/foxui.js',
        foxuiStyle: './src/scss/foxui.scss',
    },
    output: {
        filename: chunkData => {
            const name = chunkData.chunk.name.replace('Js', '');
            return `js/${name}.min.js`;
        },
        path: path.resolve(__dirname, 'dist'),
        library: 'foxui',
        clean: true,
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                    },
                },
            },
            {
                test: /\.(scss|sass)$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    {
                        loader: 'css-loader',
                        options: { url: false },
                    },
                    'sass-loader',
                ],
            },
        ],
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: chunkData => {
                const name = chunkData.chunk.name.replace('Style', '');
                return `css/${name}.min.css`;
            },
        }),
        new IgnoreEmitPlugin(/.*Style\.min\.js$/),
        new CopyPlugin({
            patterns: [
                {
                    from: 'src/fonts',
                    to: 'fonts',
                },
            ],
        }),
    ],
    mode: 'production',
};
